package com.stx_1011;

import java.io.*;

public class serializedemo {
    public static void main(String[] args) {
    
        User user = new User("hjh", 22, "male");

        
        try {
            FileOutputStream fileOut = new FileOutputStream("user.ser");
            ObjectOutputStream out = new ObjectOutputStream(fileOut);
            out.writeObject(user);
            out.close();
            fileOut.close();
            System.out.println("Serialized data is saved in user.ser");
        } catch (IOException i) {
            i.printStackTrace();
        }

     
        try {
            FileInputStream fileIn = new FileInputStream("user.ser");
            ObjectInputStream in = new ObjectInputStream(fileIn);
            User deserializedUser = (User) in.readObject();
            in.close();
            fileIn.close();

            System.out.println("Deserialized User:");
            System.out.println(deserializedUser);
        } catch (IOException i) {
            i.printStackTrace();
        } catch (ClassNotFoundException c) {
            System.out.println("User class not found");
            c.printStackTrace();
        }
    }
}
